$title Sector model

$ontext
--------------------------------------------------------------------------------
Closed 2x2 economy with specific-sector factors and Leontief function.
Laurent Cretegny, CoPS, Monash University, Australia, 2004.
--------------------------------------------------------------------------------
$offtext

$sysinclude gams-f

sets
  o                 commodity and sector          / agr, ind, srv, gov /
  f                 primary factor                / lab, cap /;

alias(o,s), (o,o1), (f,f1);

scalars
  ec                consumer substitution elasticity                  / 2 /;

Parameters
  sam(*,*)          benchmark social accounting matrix [[sam:row*row]]
  interm(o,s)       intermediate demand
  factor(f,s)       factor demand
  demand(o)         demand for consumption
  endow(f)          endowment
  supply(s)         supply of output
  cons              aggregate consumption
  tf(f,s)           tax on factor
  ep(s)             producer substitution elasticity
                                             / agr 2, ind 2, srv 2, gov 0 /;

$if not exist sector.gdx $call gdxxrw i=sector.xls o=sector.gdx index=declare
$gdxin sector.gdx
$load sam = sam
$gdxin

interm(o,s) = sam(o,s);
factor(f,s) = sam(f,s);
demand(o) = sam(o,"ra");
endow(f) = sam("ra",f);
supply(s) = sum(o, interm(o,s)) + sum(f, factor(f,s));
cons = sum(o, demand(o));
tf(f,s) = 0;

* MPSGE formulation

$ontext
$model:sector

$sectors:
  y(s)                        ! production
  c                           ! aggregate consumption
  sf(f)                       ! supply of factor

$commodities:
  p(o)                        ! price of commodity
  pc                          ! price of aggregate consumption
  pf(f)                       ! price of primary factor
  psf(f,s)$factor(f,s)$ep(s)  ! price of sector-specific factor
  ps(s)$(not ep(s))           ! price of factors for Leontief function

$consumers:
  ra                          ! representative agent income

$prod:y(s)          s:0       va:ep(s)
  o:p(s)                      q:supply(s)
  i:p(o)                      q:interm(o,s)
  i:psf(f,s)$ep(s)            q:factor(f,s)       a:ra      t:tf(f,s) va:
  i:ps(s)#(f)$(not ep(s))     q:factor(f,s)       a:ra      t:tf(f,s)

$prod:sf(f)
  o:psf(f,s)$ep(s)            q:factor(f,s)
  o:ps(s)$(not ep(s))         q:factor(f,s)
  i:pf(f)                     q:(sum(s, factor(f,s)))

$prod:c             s:ec
  o:pc              q:cons
  i:p(o)            q:demand(o)

$demand:ra
  d:pc              q:cons
  e:pf(f)           q:endow(f)

$report:
  v:r_cons(o)                 i:p(o)              prod:c
  v:r_factor(f,s)$ep(s)       i:psf(f,s)          prod:y(s)
  v:r_factors(s)$(not ep(s))  i:ps(s)             prod:y(s)

$offtext
$sysinclude mpsgeset sector

* Benchmark replication

sector.iterlim = 0;
$include sector.gen
solve sector using mcp;
abort$(abs(sector.objval) gt 1e-8) "*** sector does not calibrate ! ***";
sector.iterlim = 1000;

* Fixation of a numeraire to allow comparison

ra.fx = ra.l;

* Counterfactual : increase in endowments and increase in tax on factor

endow(f) = 1.1 * endow(f);
tf("lab","agr") = 0.1;
tf("cap",s) = 0.2;

$include sector.gen
solve sector using mcp;

* MCP formulation 

parameters
  alpha(f,s)        factor share
  beta(o)           consumption share
  theta(o,s)        production share;

alias (f,f1);

alpha(f,s)$sum(f1, factor(f1,s)) = factor(f,s)/sum(f1, factor(f1,s));
beta(o)$cons = demand(o)/cons;
theta(o,s) = interm(o,s)/(sum(o1, interm(o1,s))+sum(f, factor(f,s)));

equations
  pr_y(s)           zero profit condition for production
  pr_c              zero profit condition for consumption
  pr_sf(f)          zero profit condition for specific-sector factor
  mk_p(o)           market clearance condition for commodity
  mk_pf(f)          market clearance condition for factor
  mk_psf(f,s)       market clearance condition for sectoral factor
  mk_ps(s)          market clearance condition for sectoral factor (LT fn)
  mk_pc             market clearance condition for consumption
  inc_ra            income balance for representative agent;

pd_y_pf(f,s)        == [psf(f,s)$ep(s) + ps(s)$(not ep(s))]*(1+tf(f,s));
pva(s)              == [sum(f, alpha(f,s)*(pd_y_pf(f,s))**(1-ep(s)))**(1/(1-ep(s)))]
                       $sum(f, alpha(f,s));
cost(s)             == sum(o, theta(o,s)*p(o)) + (1-sum(o, theta(o,s)))*pva(s);
qd_y_p(o,s)         == interm(o,s);
qd_y_pf(f,s)        == factor(f,s)*(pva(s)/pd_y_pf(f,s))**ep(s);
expd                == sum(o, beta(o)*p(o)**(1-ec))**(1/(1-ec));
qd_c_p(o)           == demand(o)*(expd/p(o))**ec;

pr_y(s)..           supply(s)*p(s) =e=
                    (sum(o1, interm(o1,s))+sum(f, factor(f,s)))*cost(s);

pr_c..              cons*pc =e= sum(o, demand(o))*expd;

pr_sf(f)..          sum(s, factor(f,s)*(psf(f,s)$ep(s)+ps(s)$(not ep(s)))) =e=
                    sum(s, factor(f,s))*pf(f);

mk_p(o)..           supply(o)*y(o) =e= qd_c_p(o)*c + sum(s, qd_y_p(o,s)*y(s));

mk_pf(f)..          endow(f) =e= sum(s, factor(f,s))*sf(f);

mk_psf(f,s)$ep(s)..
                    factor(f,s)*sf(f) =e= qd_y_pf(f,s)*y(s);

mk_ps(s)$(not ep(s))..
                    sum(f, factor(f,s)*sf(f)) =e= sum(f, qd_y_pf(f,s))*y(s);

mk_pc..             cons * c * pc =e= ra;

inc_ra..            ra =e= sum(f, endow(f)*pf(f))
                    + sum((f,s)$ep(s), tf(f,s)*psf(f,s)*qd_y_pf(f,s)*y(s))
                    + sum((f,s)$(not ep(s)), tf(f,s)*ps(s)*qd_y_pf(f,s)*y(s));

model sec_mcp       / pr_y.y, pr_c.c, pr_sf.sf, mk_p.p, mk_pf.pf, mk_psf.psf,
                      mk_ps.ps, mk_pc.pc, inc_ra.ra /;

* MPSGE result replication

sec_mcp.iterlim = 0;
solve sec_mcp using mcp;
abort$(abs(sec_mcp.objval) gt 1e-8) "*** sec_mcp does not calibrate ! ***";

* Results

parameters
  res_com           results by commodity in % change from basis
  res_agg           aggregate results in % change from basis; 

res_com("output",o) = (y.l(o) - 1) * 100;
res_com("cons",o)$demand(o) = (r_cons.l(o)/demand(o) - 1) * 100;
res_com("price",o) = (p.l(o) - 1) * 100;

res_agg("c") = (c.l - 1 ) * 100;
res_agg("pc") = (pc.l - 1 ) * 100;
res_agg("ra_inc") = (ra.l/cons - 1 ) * 100;

option decimals = 6;
display res_com, res_agg;
